package com.java.dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.java.util.*;

import com.java.db.CommonConnect;

import javax.naming.NamingException;

public class LoginDao {
	Connection con = null;

	public Map login(Map requestMap) {

		HashMap map = new HashMap();
		try {
			con = (new CommonConnect()).getConnection_ds1();
			String queryStr = "call stu_login_new(?,?,?,?)";

			String param[] = new String[4];
			param[0] = (String) requestMap.get("user_id");
			param[1] = (String) requestMap.get("pwd_text");
			param[2] = (String) requestMap.get("page_gb");
			param[3] = (String) requestMap.get("local_addr");
			
			ArrayList list = null;
			list = DaoUtils.select(con, queryStr, param);
			if (list.size() == 1) {
				map = (HashMap) list.get(0);
			} else if (list.size() > 1) {
				throw new Exception("ArrayList의 사이즈가 1이상 입니다. HashMap으로 변경 불가!! 쿼리를 확인바람");
			}
		} catch (Exception ee) {
			ee.printStackTrace();
		}finally {
			try{
				if (con!=null) con.setAutoCommit(true);
				if (con!=null) con.close();
			}catch(Exception ee){}
		}
		return map;
	}

	public Map GetDefaultMenu(Map userMap) {
		HashMap map = new HashMap();
		try {
			con = (new CommonConnect()).getConnection_ds1();
			String queryStr = "call stu_getDefaultMenu_new(?)";

			String param[] = new String[1];
			param[0] = (String) userMap.get("group_id");

			ArrayList list = null;
			list = DaoUtils.select(con, queryStr, param);
			if (list.size() == 1) {
				map = (HashMap) list.get(0);
			} else if (list.size() > 1) {
				throw new Exception("ArrayList의 사이즈가 1이상 입니다. HashMap으로 변경 불가!! 쿼리를 확인바람");
			}
		} catch (Exception ee) {
			ee.printStackTrace();
		} finally {
			try{
				if (con!=null) con.setAutoCommit(true);
				if (con!=null) con.close();
			}catch(Exception ee){}
		}
		return map;
	}
}
